package StructuralPattern.Composite.SafeMode;


/**
 * @Classname : Component
 * @Description : 抽象组件
 * @Author : chentianyu
 * @Date 2023/2/19 15:34
 */


public abstract class Component {

    protected String info;  // 信息
    protected Component parent;  // 父节点


    public Component(String info) {
        this.info = info;
    }

    public void setParent(Component parent) {
        this.parent = parent;
    }

    public void getInfo() {
        System.out.println("—————————打印节点信息————————");
        System.out.println("1、本节点: " + this.info);
        if (this.parent == null) {
            System.out.println("2、父节点：无父节点，为根节点");
        } else {
            System.out.println("2、父节点：" + this.parent.info);
        }
    }

}
